Skip to content

Conversation

@DargorAbraxas
Copy link
Contributor

The documentation of the merge_and_unload() function clarifies that this is not an in-place operation. However, the developer guides code snippets shows

from transformers import AutoModelForCausalLM
from peft import PeftModel

base_model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-v0.1")
peft_model_id = "alignment-handbook/zephyr-7b-sft-lora"
model = PeftModel.from_pretrained(base_model, peft_model_id)
model.merge_and_unload()

which do not match the function documentation. The same happens with the unload() function.

This PR just changes it to be consistent and minimize silent mistakes when using the guides!

Copy link
Member

@BenjaminBossan BenjaminBossan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this and providing an update. Overall, LGTM, just a small suggestion from my side.

peft_model_id = "alignment-handbook/zephyr-7b-sft-lora"
model = PeftModel.from_pretrained(base_model, peft_model_id)
model.merge_and_unload()
merged_model = model.merge_and_unload()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's assign to the same variable. This is because after calling merge_and_unload, the original model shouldn't be used anymore.

Suggested change
merged_model = model.merge_and_unload()
model = model.merge_and_unload()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comment, @BenjaminBossan, I made the change you suggested and uploaded it. Let me know if you think there is anything else that should change!

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Member

@BenjaminBossan BenjaminBossan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, LGTM.

@BenjaminBossan BenjaminBossan merged commit 6bf24ac into huggingface:main Oct 27, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants